//
//  SIXTabBarViewController.m
//  weibo
//
//  Created by chenangel on 16/5/20.
//  Copyright © 2016年 chuhan. All rights reserved.
//

#import "SIXTabBarViewController.h"
#import "SIXNavigationController.h"

#import "SIXHomeController.h"
#import "SIXMessageController.h"
#import "SIXPulishViewController.h"
#import "SIXDiscoverController.h"
#import "SIXMeController.h"
#import "SIXTabBar.h"

@interface SIXTabBarViewController ()

@end

@implementation SIXTabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //初始化创建子控制器
    [self setUpAllChildrens];

}
- (void)setUpAllChildrens{
    SIXHomeController *home = [[SIXHomeController alloc]init];
    [self addChildViewController:home title:@"首页" image:@"tabbar_home" selImage:@"tabbar_home_selected"];
    
    
    SIXMessageController *messageCenter = [[SIXMessageController alloc] init];
    [self addChildViewController:messageCenter title:@"消息" image:@"tabbar_message_center" selImage:@"tabbar_message_center_selected"];
    
    
    SIXDiscoverController *discover = [[SIXDiscoverController alloc] init];
    [self addChildViewController:discover title:@"发现" image:@"tabbar_discover" selImage:@"tabbar_discover_selected"];
    
    
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"SIXMeController" bundle:nil];
    SIXMeController *profile = [storyboard instantiateInitialViewController];
    [self addChildViewController:profile title:@"我" image:@"tabbar_profile" selImage:@"tabbar_profile_selected"];
    
    [SIXNoteCenter addObserver:self selector:@selector(pulish) name:@"pulish" object:nil];
    
    [self setValue:[[SIXTabBar alloc]init] forKey:@"tabBar"];
    
}
- (void)pulish{
    SIXPulishViewController *vc =[[SIXPulishViewController alloc]init];
    [self presentModalViewController:vc animated:YES];
    
}

//添加子控制器
-(void)addChildViewController:(UIViewController *)childVc  title:(NSString *)title image:(NSString *)image selImage:(NSString *)selImage {
    
    //设置子控制器的TabBarButton属性
    childVc.title = title;
    childVc.tabBarItem.image = [UIImage imageNamed:image];
    childVc.tabBarItem.selectedImage = [[UIImage imageNamed:selImage] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    NSMutableDictionary *AttrDic = [NSMutableDictionary dictionary];
    
    AttrDic[NSForegroundColorAttributeName] = [UIColor grayColor];
    
    [childVc.tabBarItem setTitleTextAttributes:AttrDic forState:UIControlStateNormal];
    
    NSMutableDictionary *selAttr = [NSMutableDictionary dictionary];
    
    selAttr[NSForegroundColorAttributeName] = [UIColor orangeColor];
    
    [childVc.tabBarItem setTitleTextAttributes:selAttr forState:UIControlStateSelected];
    
    if(![title isEqualToString:@"发现"]){
        //让子控制器包装一个导航控制器
        SIXNavigationController *nav = [[SIXNavigationController alloc]initWithRootViewController:childVc];
        [self addChildViewController:nav];
    }else{
        [self addChildViewController:childVc];
    }

    
    
    
}

@end
